
// pending
// ->
// resolve(成功) fulfilled || reject(失败) rejected

let str = 'hello'

/*
Promise.resolve(str)
Promise.reject(str)
// Promise.resolve(str).then(res => {
Promise.reject(str).catch(res => {
  console.log(res)
})*/


const p1 = (data) => {
  return new Promise((resolve, reject) => {
    setTimeout(function () {
      // resolve(data)
      reject(data)
    }, 1000)
  })
}

/*
p1('我是p1').then(res => {
  console.log(res)
}).catch(e => console.log(e))
*/



// new 一个 Promise 对象的实例

let p = new Promise((resolve, reject) => {
  setTimeout(() => {
    // resolve('我是resolve的数据')
    reject('我是reject')
  }, 3000)
})



/*
// 谁最块 race 的最终状态就是谁
Promise.race([p, p1('race')]).then(res => {
  console.log(res)
}).catch(e => {
  console.log(e)
})*/

/*
// p && p1 都成功 all =》 fulfilled
// p || p1  有一个失败 all =》 rejected
Promise.all([p, p1('all')]).then(res => {
  console.log(res)
}).catch(e => {
  console.log(e)
})*/

/*
// p && p1 都失败 any =》 rejected
// p || p1  有一个成功 any =》 fulfilled
Promise.any([p, p1('eny')]).then(res => {
  console.log(res)
}).catch(e => {
  console.log(e)
})*/


/*

p.then((res) => {
  // resolve
  console.log(res)
}, e => {
  // reject
  console.log(e)
}).finally(() => {
  console.log('over!!!')
})*/


/*
p.then((res) => {
  // resolve
  console.log(res)
}).catch(e => {
  // reject
  console.log(e)
}).finally(() => {
  console.log('over!!!')
})*/



// console.log(p)



